package com.itheima;

import java.util.Random;

public class ArrayDemo {
    //二维数组的打乱
    public static void main(String[] args) {
        int[][] number = {
                {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12},
                {13,14,15,16}
        };
        //打乱数组
        shuffle(number);
        for(int i=0;i<number.length;i++){
            for(int j=0;j<number[i].length;j++){
                System.out.print(number[i][j] + "\t");
            }
            System.out.println();
        }
    }

    //打乱数组
    public static void shuffle(int[][] number){
        Random random = new Random();
        for(int i=0;i<number.length;i++){
            for(int j=0;j<number[i].length;j++){
                int index1 = random.nextInt(number.length);
                int index2 = random.nextInt(number[index1].length);
                int temp = number[i][j];
                number[i][j] = number[index1][index2];
                number[index1][index2] = temp;
            }
        }
    }
}
